#include <omp.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int i,x,y,z=5;
printf("Before threads do work:\n");
#pragma omp parallel num_threads(3) shared(z) private(i,x,y)
{
printf(" thread %d is working\n",omp_get_thread_num());
x=y=1;
if (omp_get_thread_num()==1) {
z=10;x=4;
}
for ( i=0; i<2; i++) {
printf(" thread %d is doing more work. x+y+z=%i\n",omp_get_thread_num(),x+y+z);
}
}
printf("After threads do work\n");
return 0;
}
Two Runs